package com.zzg.srb.core.controller.api;


import com.zzg.srb.common.result.R;
import com.zzg.srb.core.entity.pojo.BorrowInfo;
import com.zzg.srb.core.service.BorrowInfoService;
import com.zzg.srb.core.utils.CurrentLoginUserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author zhengzg
 * @since 2022-05-27
 */
@Api(tags = "借款信息")
@RestController
@RequestMapping("/api/core/borrowInfo")
public class BorrowInfoController {

    private Logger log = LoggerFactory.getLogger(BorrowInfoController.class);

    @Resource
    private BorrowInfoService borrowInfoService;

    @ApiOperation("获取借款额度")
    @GetMapping("/auth/getBorrowAmount")
    public R getBorrowAmount(){
        Long userId = CurrentLoginUserUtils.getLoginUser();
        BigDecimal borrowAmount = borrowInfoService.getBorrowAmount(userId);
        return R.ok().data(borrowAmount);
    }

    @ApiOperation("提交借款申请")
    @PostMapping("/auth/save")
    public R save(@RequestBody BorrowInfo borrowInfo){
        log.info("提交借款申请 ============> BorrowInfoController.save: " + borrowInfo);
        Long userId = CurrentLoginUserUtils.getLoginUser();
        borrowInfoService.saveBorrowInfo(borrowInfo,userId);
        return R.ok().message("提交成功");
    }

    @ApiOperation("获取借款申请审批状态")
    @GetMapping("/auth/getBorrowInfoStatus")
    public R getBorrowInfoStatus(){
        Long userId = CurrentLoginUserUtils.getLoginUser();
        return R.ok().data(borrowInfoService.getStatusByUserId(userId));
    }
}

